<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ajax Post请求</title>
    <style>
        #result{
            width: 200px;
            height: 100px;
            border: solid 1px #90b;
        }
    </style>
</head>
<body>
<button>点击发送请求</button>
<div id="result"></div>
<script>
    //点击按钮,将响应的内容返回回来做呈现
        const btn=document.querySelector('button')
    btn.addEventListener("click", function () {
        const xhr=new XMLHttpRequest()
        xhr.open('POST','http://localhost:8000/server')
        //传递post请求的参数
        // xhr.send('a:200&b:300')
        xhr.send('a=200&b=300')
        xhr.onreadystatechange=function () {
            if (xhr.readyState===4){
                if (xhr.status>=200&&xhr.status<300){
                    console.log(xhr.status)
                    console.log(xhr.statusText)
                    console.log(xhr.getAllResponseHeaders())
                    console.log(xhr.response)
                    document.querySelector('div').innerHTML=`${xhr.response}`
                }
            }

        }
    })
</script>
</body>
</html>